<!--
 * @FilePath     : /study_code/layui/19-2-6.html
 * @Description  : 展开/折叠节点
 * @Date         : 2025-04-14 15:57:56
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-14 16:16:34
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="/layui/dist/css/layui.css" />
    <!-- css 是 treetable.js 中 js 代码追加 -->
  </head>
  <body>
    <button class="btn1">展开所有节点</button>
    <br />
    <button class="btn2">折叠所有节点</button>

    <hr />

    <table id="table1" class="layui-table" lay-filter="table1"></table>

    <script src="/layui/dist/layui.js"></script>
    <script src="/layui/treetable-lay/common.js"></script>
    <script>
      layui
        .config({
          base: '/layui/extends_modules',
        })
        .extend({
          treetable: '/treetable-lay/treetable',
        })
        .use(['form', 'treetable', 'layer'], function () {
          var layer = layui.layer,
            form = layui.form,
            $ = layui.jquery,
            treetable = layui.treetable

          // 默认配置项见 https://gitcode.com/fangyinggui/study_code/blob/main/layui/treetable-lay/common.js
          treetable.render({
            ...defaultConfig,
            ...{
              id: 'fygtest',
              // treeColIndex: 2, // 树表图标设置在第3列（从0开始）
            },
          })

          $('.btn1').on('click', function () {
            console.log('触发')
            /**
             * @brief: 展开所有节点
             * @param {strign} selector 树表渲染到的 table 元素的 id 选择器
             * @return {*}
             */
            // treetable.expandAll(selector)
            treetable.expandAll('#table1')
          })

          $('.btn2').on('click', function () {
            treetable.foldAll('#table1')
          })
        })
    </script>
  </body>
</html>
